package de.duester.vectordrawing.object;

import de.duester.vectordrawing.GraphicalObject;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint.Style;
import android.graphics.PointF;

/**
 * @author Maxim Duester
 */
public class Circle extends Ellipse {
	private float radius;

	/**
	 * 
	 */
	public Circle() {
	}

	/**
	 * @param center
	 * @param radius
	 */
	public Circle(PointF center, float radius) {
		super(new PointF(center.x - radius + 1, center.y - radius + 1), 2 * radius - 1,
				2 * radius - 1);
		this.radius = radius;
	}

	/**
	 * @return
	 */
	public float getRadius() {
		return radius;
	}

	/* (non-Javadoc)
	 * @see de.duester.vectordrawing.object.Ellipse#getNonRotatedImage()
	 */
	@Override
	protected Bitmap getNonRotatedImage() {
		paint.setStyle(Style.FILL);
		paint.setColor(getColor(1));

		PointF p = getScaledAndTransformedRelative(new PointF(getWidth(), getWidth()));
		float d = p.x;
		float r = d / 2;

		Bitmap b = Bitmap.createBitmap((int) d, (int) d, Config.ARGB_8888);
		Canvas canvas = new Canvas(b);
		canvas.drawCircle(r, r, r, paint);

		paint.setStyle(Style.STROKE);
		paint.setColor(getColor(0));

		canvas.drawCircle(r, r, r, paint);
		return b;
	}

	/* (non-Javadoc)
	 * @see de.duester.vectordrawing.GraphicalObject#getRotatedImage()
	 */
	@Override
	protected Bitmap getRotatedImage() {
		return getNonRotatedImageCache();
	}

	/* (non-Javadoc)
	 * @see de.duester.vectordrawing.object.Arc#copy()
	 */
	@Override
	public GraphicalObject copy() {
		Circle c = (Circle) super.copy();
		c.radius = radius;
		return c;
	}

	/* (non-Javadoc)
	 * @see de.duester.vectordrawing.object.Arc#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object o) {
		if (!super.equals(o))
			return false;
		Circle c = (Circle) o;
		return (radius == c.radius);
	}
}
